﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HRMSys.Model;
using System.Data.SqlClient;
using System.Data;

namespace HRMSys.DAL
{
    public class IdNameDAL
    {
        public IdName[] GetByCategory(string category) 
        {
            string sql = "select * from T_IdName where Category=@Category";
            SqlParameter categoryParam = new SqlParameter("@Category", category);
            DataTable table = SqlHelper.ExecuteDataTable(sql, categoryParam);
            int dataCount = table.Rows.Count;
            IdName[] idNames = new IdName[dataCount];
            for (int i = 0; i < dataCount; i++)
            {
                DataRow row = table.Rows[i];
                idNames[i] = this.ToIdName(row);
            }
            return idNames;
        }

        private IdName ToIdName(DataRow row) 
        {
            IdName idName = new IdName();
            idName.Id = (Guid)row["Id"];
            idName.Name = (string)row["Name"];
            idName.Category = (string)row["Category"];
            return idName;
        }
    }
}
